<!DOCTYPE html>
<html lang="en">

<head style="overflow:scroll">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta http-equiv="x-dns-prefetch-control" content="on">
    <!-- <meta http-equiv="X-Frame-Options" content="ALLOW-FROM"> -->
    <title>享优乐净水器新品发布会直播抽奖</title>


    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/fastclick.js"></script>
    <script>
        $(function() {
            FastClick.attach(document.body);
        });
    </script>
    <script type="text/javascript" src="./js/layer.m.js"></script>
    <script type="text/javascript" src="./js/md5.js"></script>

    <link rel="stylesheet" href="./lib/css/jquery-weui.min.css" />
    <link rel="stylesheet" href="./style/base.css" />
    <link rel="stylesheet" href="./style/layer.css"/>

    
    <script type="text/javascript" src="./lib/js/jquery-weui.min.js"></script>
</head>

<body id="container" style="overflow:scroll">
    <div class="fixed background" id="img_background"></div>
    <div class="content_jgg">
        <div class="content">
            <div id="lottery">
                <div class="cjqy">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td class="lottery-unit lottery-unit-0">
                                    <div class="img_tab"><img src="./image/new/p0.png" id="topLeft" class="topLeft">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                                <td class="lottery-unit lottery-unit-1">
                                    <div class="img_tab"><img src="./image/new/p1.png" id="topCenter" class="topCenter">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                                <td class="lottery-unit lottery-unit-2">
                                    <div class="img_tab"><img src="./image/new/p2.png" id="topRight" class="topRight">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="lottery-unit lottery-unit-7">
                                    <div class="img_tab"><img src="./image/new/p7.png" id="middleLeft"
                                            class="middleLeft">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                                <td class="click_tab">
                                    <div id="click" class="img_tab">
                                        <img class="img1" src="./image/new/jggcj1.png">
                                        <img class="img2" style="display: none" src="./image/new/jggcj.png"
                                            id="middleCenter" class="middleCenter">
                                    </div>
                                </td>
                                <td class="lottery-unit lottery-unit-3">
                                    <div class="img_tab"><img src="./image/new/p3.png" id="middleRight"
                                            class="middleRight">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="lottery-unit lottery-unit-6">
                                    <div class="img_tab"><img src="./image/new/p6.png" id="bottomLeft"
                                            class="bottomLeft">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                                <td class="lottery-unit lottery-unit-5">
                                    <div class="img_tab"><img src="./image/new/p5.png" id="bottomMiddle"
                                            class="bottomMiddle">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                                <td class="lottery-unit lottery-unit-4">
                                    <div class="img_tab"><img src="./image/new/p4.png" id="bottomRight"
                                            class="bottomRight">
                                        <div class="mask"></div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <h2 style="font-size:18px;text-align:center" id="lotteryTimes"></h2>

            <div class="goHistory">
                <span class="history-btn"></span>
            </div>
            <div class="cj_explain">
                <img class="img_hei" src="./image/new/role.png">
                <div class="t_content" style="margin-top: 2rem;">
                    <h6 class="gradient-bg">活动时间</h6>
                    <p>2018年10月13日上午09:15至直播结束</p>
                    <h6 class="gradient-bg">活动规则</h6>
                    <p>1、直播期间，持卡人通过直播页面、电视盒子二维码进入抽奖页面即可进行抽奖。</p>
                    <p>2、每个持卡人可在直播期间参与抽奖，每人仅有一次抽奖机会。</p>
                    <p>3、抽奖获得的奖品发放安排如下：</p>
                    <div style="margin-left:1rem;">
                        <p>•　实物奖品：中奖后需填写收货信息，预计2周内邮寄；</p>
                        <p>•　纷享币：中奖后2周内发放，可登录纷享荟“我的”进行查询。</p>
                    </div>
                    <p>4、抽奖人数太多时，可能会出现系统限流情况，请稍等后重新进入。</p>
                </div>
            </div>
        </div>
    </div>
    <div class="loading-bar hidden"> </div>


    <script>
        function loading(isOpen) {
            $('.loading-bar')[isOpen ? 'removeClass' : 'addClass']('hidden');
        }
        // loading(1);
    </script>
    <script type="text/javascript" src="./lib/js/city_new.min.js"></script>
    <script type="text/javascript" src="./lib/js/cityPicker.js"></script>
    <script type="text/javascript" src="./js/commonWithNestCloud.js"></script>
 
    <script type="text/javascript">
        var awardsCode;

        $(".startNotice  .button").on("click", function () {
            layer.closeAll();
            getLotteryCount();
        })
        //获取url参数
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return r[2];
            return null;
        }

        function trim(str) { //删除左右两端的空格
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }

        //清楚本地缓存
        var clearData = getQueryString("clearData") ? getQueryString("clearData") : false,
            setTestTime = getQueryString("setStatus") ? getQueryString("setStatus") : 0;

        if (setTestTime == 1) {
            common.startTime = 1;
            common.endTime = 1000000000000000000000000000;
        }


        if (clearData) {
            localStorage.clear();
            sessionStorage.clear();
        }
        //获取本地缓存数据
        var isLogin = localStorage.getItem("isLogin") ? JSON.parse(localStorage.getItem("isLogin")) : {
                login: 0,
                staffNum: ""
            },
            drawMsg = "";
        common.staffNum = isLogin.staffNum;


        //抓取接口错误404,503,500
        $(document).ajaxError(function (event, jqXHR, options, errorMsg) {
            console.log(jqXHR.status);
            if (jqXHR.status == 503 || jqXHR.status == 500 || jqXHR.status == 0) {
                layer.closeAll();
                getLotteryCount();
                layer.open({
                    type: 3,
                    title: '温馨提示',
                    className: 'errortNotice',
                    content: '<div class="notice">' + common.notice1 +
                        '</div><div class="button">确定</div>',
                    style: 'width:17rem; background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                    shadeClose: false
                });
                $(".errortNotice  .button").on("click", function () {
                    location.reload();
                })
            }
        });

        //转盘
        var lottery = {
            index: -1, //当前转动到哪个位置，起点位置
            count: 0, //总共有多少个位置
            timer: 0, //setTimeout的ID，用clearTimeout清除
            speed: 20, //初始转动速度
            times: 0, //转动次数
            cycle: 100, //转动基本次数：即至少需要转动多少次再进入抽奖环节
            minCycle: 50,
            maxCycle: 100,
            prize: -1, //中奖位置
            isStoped: false,
            data: {},
            init: function (id) {
                if ($("#" + id).find(".lottery-unit").length > 0) {
                    $lottery = $("#" + id);
                    $units = $lottery.find(".lottery-unit");
                    this.obj = $lottery;
                    this.count = $units.length;
                    $lottery.find(".lottery-unit-" + this.index).addClass("active");
                };
            },
            roll: function () {
                var index = this.index;
                var count = this.count;
                var lottery = this.obj;
                console.log("index===" + index);
                $(lottery).find(".lottery-unit-" + index).removeClass("active");
                $(".lottery-unit").find(".mask").show();
                index += 1;
                if (index > count - 1) {
                    index = 0;
                };
                console.log(index);
                $(lottery).find(".lottery-unit-" + index).addClass("active");
                $(" #lottery .active").find(".mask").hide();
                this.index = index;
                return false;
            },
            stop: function (index) {
                this.prize = index;
                return false;
            },
            reset: function () {
                this.speed = 20; //初始转动速度
                this.times = 0; //转动次数
                this.cycle = 100; //转动基本次数：即至少需要转动多少次再进入抽奖环节
                this.prize = -1; //中奖位置
                this.isStoped = false;
            },
            stopAndInit: function () { // 停止转动并且恢复到初始状态
                clearTimeout(this.timer);
                $("#click .img1").show();
                $("#click .img2").hide();
                this.reset();
                this.obj.find(".lottery-unit").removeClass("active");
                this.obj.find(".mask").hide();
            }
        };


        //转盘停止转动 isInit为true时 停止转动 不抽奖 跳转页面或者 抽奖失败时初始化
        function stopRoll() {
            clearTimeout(lottery.timer);
            lottery.reset();
            $("#click .img1").show();
            $("#click .img2").hide();
            var msg = ""
            window.canDraw = true;
            console.log("status=" + lottery.data.status);
            if (lottery.data.status == "1") {
                msg = "恭喜您获得<b>" + lottery.data.title + "</b>!<br/>请填写收货地址，公司将在2周内配送，请确保信息正确并保持电话畅通，谢谢！";
            } else if (lottery.data.status == "2") {
                msg = "恭喜您获得<b>" + lottery.data.title + "</b>!<br/>公司将在2周内电话与您联系领奖事宜，请保持电话畅通，谢谢！";
            } else if (lottery.data.status == "0") {
                msg = "恭喜您获得<b>" + lottery.data.title + "</b>!<br/>公司将在2周内发放，后期可登录纷享荟“我的”进行查询，谢谢！";
            } else if (lottery.data.status == "4") {
                msg = "很遗憾未中奖，感谢您的参与！"
            }
            if (awardsCode == "8080") {
                msg = "很遗憾未中奖，感谢您的参与！"
            }
            console.log(lottery.data);
            setTimeout(function () {
                layer.open({
                    title: '温馨提示',
                    className: 'drawNotice',
                    content: '<div class="zjnotice">' + msg + '</div>' + (lottery.data.status == "1" ? '<div class="address_modal"><a class="addressModal" style="color: inherit;display:inline;margin-left:10px"' + 'data-quali="'
                         + localStorage.getItem("qualiSeqNo") + '"' + 'class="addressModal" href="javascript:void(0);' + '">' + '点此填写收货地址</a>' + '</div>' : '<div class="button">' +'关闭' + '</div>'),
                    style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                    shadeClose: false,
                    end: function () {

                    }
                });
                $(".drawNotice  .button").on("click", function () {
                    // layer.close(2);
                    layer.closeAll();
                    getLotteryCount();
                })
                
            }, 0)
        }

        //转盘开始转动
        function roll() {
            lottery.times += 1;
            lottery.roll(); //转动过程调用的是lottery的roll方法，这里是第一次调用初始化
            if (lottery.times > lottery.cycle + 10 && lottery.prize == lottery.index) {
                console.log("stopRoll");
                stopRoll(); //停止
                click = false;
            } else {
                if (lottery.isStoped) {
                    if (lottery.times >= lottery.minCycle && lottery.cycle == lottery.maxCycle) {
                        lottery.cycle = lottery.times;
                        console.log("positon" + lottery.data.position);
                        // lottery.prize = Number(lottery.data.position);
                        switch (lottery.data.position) {
                            case 'topLeft':
                                lottery.prize = 0;
                                break;
                            case 'topCenter':
                                lottery.prize = 1;
                                break;
                            case 'topRight':
                                lottery.prize = 2;
                                break;
                            case 'middleLeft':
                                lottery.prize = 7;
                                break;
                            case 'middleRight':
                                lottery.prize = 3;
                                break;
                            case 'bottomLeft':
                                lottery.prize = 6;
                                break;
                            case 'bottomMiddle':
                                lottery.prize = 5;
                                break;
                            case 'bottomRight':
                                lottery.prize = 4;
                                break;
                        }
                    }
                }
                if (lottery.times < lottery.cycle) {
                    lottery.speed -= 10;
                } else if (lottery.times > lottery.cycle) {
                    if (lottery.times > lottery.cycle + 10 && ((lottery.prize == 0 && lottery.index == 7) || lottery
                            .prize ==
                            lottery.index + 1)) {
                        lottery.speed += 110;
                    } else {
                        lottery.speed += 20;
                    }
                }
                if (lottery.speed < 40) {
                    lottery.speed = 40;
                };
                lottery.timer = setTimeout(function () {
                    roll()
                }, lottery.speed); //循环调用

            }
            return false;
        }

        var click = false;
        lottery.init('lottery');

        //开始抽奖
        function startDraw() {


            if (window.restCount === "0") {

                layer.open({
                    type: 3,
                    title: [
                        '温馨提示',
                        'background-color:transparent; color:black; text-align:center;'
                    ],
                    className: 'startNotice',
                    content: '<div class="zjnotice">' + '您抽奖已超过指定次数' + '</div><div class="button">' + ('关闭') + '</div>' + (common.skipUrl ? '<div class="button">' + '<a style="text-decoration: none; color: #ff8800;" href="' + common.skipUrl  + '">返回</a>' + '</div>' : ''),
                    style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                    shadeClose: false,
                    end: function () {
                        // location.href = common.skipUrl;
                    }
                });
                $(".startNotice  .button").on("click", function () {
                    layer.closeAll();
                })

                $(".startNotice #checkHistory").on("click", function () {
                    $(".history-btn").click();
                })

                return;
            }

            window.canDraw = false;

            var t = +new Date();
            var dealerNo = JSON.parse(localStorage.getItem("isLogin")).staffNum;
            var urlSplit = window.location.href.split("/");
            $.ajax({
                type: 'get',
                url: common.url + "/lottery/act?dealerNo=" + dealerNo,
                success: function (data) {
                    if (data && (data.code === 40005 || data.code === 40006)) {
                        lottery.stopAndInit();
                        layer.open({
                            type: 3,
                            title: '温馨提示',
                            className: 'againNotice',
                            content: '<div class="notice">' + (data.code === 40005 ?
                                    '抽奖活动尚未开始，敬请期待！' : '抽奖活动已结束，感谢关注！') +
                                '</div><div class="button">确定</div>',
                            style: 'width:18rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                            shadeClose: false,
                            end: function () {
                                click = false;
                            }
                        });
                        $(".againNotice  .button").on("click", function () {
                            layer.closeAll();
                        })
                        window.canDraw = true;
                        getLotteryCount();
                    }
                    if (data && data.code == 40002) {
                        layer.open({
                            type: 3,
                            title: '温馨提示',
                            className: 'errortNotice',
                            content: '<div class="notice">卡号未登录，请稍后再试！</div><div class="button">确定</div>',
                            style: 'width:17rem; background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;height:10rem!important',
                            shadeClose: false,
                        });
                        $(".errortNotice  .button").on("click", function () {
                            location.reload();
                        })
                        window.canDraw = true;
                        getLotteryCount();
                    } else if (data && data.code == 0) {
                        //move here
                        lottery.speed = 100;
                        $("#click .img1").hide();
                        $("#click .img2").show();
                        roll(); //转圈过程不响应click事件，会将click置为false
                        console.log(common);
                        awardsCode = data.content.awardsCode;
                        lottery.data = common.prize[data.content.awardsCode];
                        localStorage.setItem("qualiSeqNo", data.content.qualiSeqNo);
                        lottery.data.title = data.content.awardsName;
                        lottery.isStoped = true;
                        window.canDraw = true;
                        getLotteryCount();
                    } else if (data && data.code == 40007) { //超过次数
                        layer.open({
                            type: 3,
                            title: [
                                '温馨提示',
                                'background-color:transparent; color:black; text-align:center;'
                            ],
                            className: 'startNotice',
                            content: '<div class="zjnotice">' + '您抽奖已超过指定次数' +
                            '</div><div class="button">' + (
                                '<a style="text-decoration: none; color: #ff8800;" href="javascript:void(0);" id="checkHistory">查看中奖记录</a>'
                            ) + '</div>',
                            style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                            shadeClose: false,
                            end: function () {
                                // location.href = common.skipUrl;
                            }
                        });
                        $(".startNotice  .button").on("click", function () {
                            layer.closeAll();
                        })

                        $(".startNotice #checkHistory").on("click", function () {
                            $(".history-btn").click();
                        })

                        window.canDraw = true;
                        getLotteryCount();

                    } else if (data && data.code == 40008) { //没有抽奖资格
                        layer.open({
                            type: 3,
                            title: [
                                '温馨提示',
                                'background-color:transparent; color:black; text-align:center;'
                            ],
                            className: 'startNotice',
                            content: '<div class="zjnotice">你已没有抽奖资格</div><div class="button">关闭</div>' + (common.skipUrl ? '<div class="button">' + '<a style="text-decoration: none; color: #ff8800;" href="' + common.skipUrl  + '">返回</a>' + '</div>' : ''),
                            style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                            shadeClose: false,
                            end: function () {
                                // location.href = common.skipUrl;
                                console.log("suck????????");
                            }
                        });
                        $(".startNotice  .button").on("click", function () {
                            layer.closeAll();
                        })
                        window.canDraw = true;
                        getLotteryCount();
                    } else if (data && data.code == 40003) { //未中奖
                        window.canDraw = true;
                        layer.open({
                            type: 3,
                            title: [
                                '温馨提示',
                                'background-color:transparent; color:black; text-align:center;'
                            ],
                            className: 'startNotice',
                            content: '<div class="zjnotice">未中奖</div><div class="button">关闭</div>' + (common.skipUrl ? '<div class="button">' + '<a style="text-decoration: none; color: #ff8800;" href="' + common.skipUrl  + '">返回</a>' + '</div>' : ''),
                            style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                            shadeClose: false,
                            end: function () {
                                // location.href = common.skipUrl;
                                console.log("suck???");
                            }
                        });
                        $(".startNotice  .button").on("click", function () {
                            layer.closeAll();
                        })
                        window.canDraw = true;
                        getLotteryCount();
                    }
                },

            });
        }


        function getLotteryCount() {
            if (JSON.parse(localStorage.getItem("isLogin")) && JSON.parse(localStorage.getItem("isLogin")).login !==
                0) {
                $.ajax({
                    type: 'get',
                    url: common.url + "/auldraw/quali/count?dealerNo=" + JSON.parse(localStorage.getItem(
                        "isLogin")).staffNum,
                    success: function (data) {
                        $("#lotteryTimes").html("您还有" + data.content.count + "次抽奖机会");
                        window.restCount = data.content.count
                    },
                });

            }
        }

        window.canDraw = true;
        //登录相关操作
        function alertLayer() {

            if (common.deploycolId !== localStorage.getItem("deploycolId")) {
                localStorage.removeItem("isLogin");
            }

            var isLogin = localStorage.getItem("isLogin") ? JSON.parse(localStorage.getItem("isLogin")) : {
                login: 0,
                staffNum: ""
            };
            if (isLogin.login == 0) { //未登陆
                login(1);
            } else { //已登录
                if (window.restCount === "0") {
                    window.canDraw = true;
                }
                if (window.canDraw) {
                    startDraw();
                }
            }
        }

        // 登录框   1为点击抽奖时  登录   2为点击查看历史登录
        function login(type) {
            layer.open({
                type: 3,
                title: [
                    '登录您的账号',
                    'background-color:transparent; color:black; text-align:center;'
                ],
                className: 'login-popuo',
                // content: '<div class="pwd"><input class="staffNum" name="staffNum" type="tel" placeholder="请输入您的卡号" /></div><div class="pwd"><input class="password" name="password" type="password" placeholder="请输入您的密码" /></div><p class="error"></p><div class="button" data-type=' + type + '>登录</div>',
                content: '<div class="pwd"><input class="staffNum" name="staffNum" type="tel" placeholder="请输入您的卡号"/></div><div class="pwd"><input class="password" name="password" type="password" placeholder="请输入您的密码" /></div><p class="error"></p><div class="button" data-type=' + type + '>登录</div><div class="button" style="margin-top:10px">关闭</div>',
                style: 'width:17rem; min-height:12.5rem; background-color:#fff; color:black; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                shadeClose: false
            });
        }

        function loading(isOpen) {
            $('.loading-bar')[isOpen ? 'removeClass' : 'addClass']('hidden');
        }
        // 登录监听
        // mai 登录接口
        $('#container').on("click", ".login-popuo .button", function (e) {
            var current = $(e.currentTarget);
            var container = current.closest('.login-popuo');
            var inputVal1 = trim(container.find(".staffNum").val()),
                inputVal2 = trim(container.find(".password").val());
            var type = current.attr('data-type');
            var t = +new Date();

            if (!type) {
                layer.closeAll();
                return;
            }



            if (JSON.parse(localStorage.getItem("isLogin")) && JSON.parse(localStorage.getItem("isLogin"))
                .login !== 0) {
                return;
            }

            if (window.isLogined) {
                return;
            }

            var urlSplit = window.location.href.split("/");
            if (inputVal1 != "" && inputVal2 != "") {
                $.ajax({
                    type: "post",
                    url: common.url + "/sys/login",
                    dataType: "json",
                    data: {
                        dealerNo: inputVal1,
                        password: hex_md5(inputVal2)
                    },
                    beforeSend: function () {
                        loading(1);
                        window.isLogined = true;
                    },
                    complete: function () {
                        loading();
                    },
                    success: function (data) {
                        /* 
                            40005 活动未开始 不可登录
                            40006 活动已结束 可登陆
                        */
                        if (data && data.code === 40006) {
                            common.staffNum = inputVal1;
                            localStorage.setItem("isLogin", JSON.stringify({
                                login: 1,
                                staffNum: common.staffNum
                            })); //保存登录信息

                            localStorage.setItem("deploycolId", common.deploycolId);

                        }
                        if (type == 2) {
                            // location.href = './history.html';
                            return;
                        }
                        if (data && (data.code === 40005 || data.code === 40006)) {
                            layer.open({
                                type: 3,
                                title: '温馨提示',
                                className: 'againNotice',
                                content: '<div class="notice">' + (data.code === 40005 ?
                                        '抽奖活动尚未开始，敬请期待！' : '抽奖活动已结束，感谢关注！') +
                                    '</div><div class="button">确定</div>',
                                style: 'width:18rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                                shadeClose: false,
                                end: function () {
                                    click = false;
                                }
                            });
                            $(".againNotice  .button").on("click", function () {
                                layer.closeAll();
                                getLotteryCount();
                            })
                        }
                    },
                    error: function (data) {
                        if (data.status == 400) {
                            // 1为点击抽奖时  登录   2为点击查看历史登录
                            if (type == 1 && data.responseText == '您已抽过奖') {
                                layer.open({
                                    type: 3,
                                    title: [
                                        '温馨提示',
                                        'background-color:transparent; color:black; text-align:center;'
                                    ],
                                    className: 'againNotice',
                                    content: '<div class="zjnotice">您已经抽过奖了，不能重复抽奖，谢谢！</div><div class="button">确定</div>',
                                    style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                                    shadeClose: false,
                                    end: function () {
                                        // location.href = common.skipUrl;
                                    }
                                });
                            } else {
                                container.find('.error').addClass('red').text('*卡号或密码不正确，请重新输入');
                                console.log(data);
                            }
                            $(".againNotice  .button").on("click", function () {
                                layer.closeAll();
                                getLotteryCount();
                            })
                            window.isLogined = false;
                        } else if (data.status == 200) {
                            layer.closeAll();
                            common.staffNum = inputVal1;
                            localStorage.setItem("isLogin", JSON.stringify({
                                login: 1,
                                staffNum: common.staffNum
                            })); //保存登录信息
                            localStorage.setItem("deploycolId", common.deploycolId);
                            getLotteryCount();
                            window.canDraw = true;
                            if (type == 1) { // 点击抽奖登录 成功后直接抽奖
                                console.log("errorIn");
                                // startDraw();
                            } else { // 点击 中奖纪录登录  成功后跳转
                                // location.href = './history.html';
                            }
                            window.isLogined = true;
                        } else {
                            window.isLogined = false;
                        }
                    }
                })

            } else {
                container.find('.error').addClass('red').text('*' + (!inputVal1 ? '卡号' : '密码') + '不能为空');
            }
        })

        //点击开始抽奖按钮
        $("#lottery #click").click(function () {

            alertLayer();
        });
        $(".history-btn").click(function (e) {
            var isLogin = localStorage.getItem("isLogin") ? JSON.parse(localStorage.getItem("isLogin")) : {
                login: 0,
                staffNum: ""
            };
            if (isLogin && isLogin.login == 1) {

                $.ajax({
                    url: common.url + "/auldraw/winner/record?dealerNo=" + JSON.parse(localStorage
                        .getItem("isLogin")).staffNum,
                    type: 'GET',
                    dataType: "json",
                    success: function (data) {

                        if (data && data.content) {

                            if (Object.keys(data.content).length !== 0) {

                                var str = "";

                                var keys = Object.keys(data.content);

                                for (var i = 0; i < keys.length; i++) {

                                    var realityString = '';

                                    var virtualString = '';

                                    if (common.prize[data.content[keys[i]].giftCode] && common.prize[data.content[keys[i]].giftCode].status === "1") {

                                        if (!data.content[keys[i]]["detailAddress"]) {
                                            realityString =
                                                '<a style="color: inherit;display:inline;margin-left:10px"' +
                                                'data-quali="' + keys[i] + '"' +
                                                'class="addressModal" href="javascript:void(0);' +
                                                '">' + '点此填写收货地址</a>'
                                        } else {
                                            realityString =
                                                '<a class="addressDetailModal" style="color: inherit;margin-left:10px;display:inline"' + 'data-name="' + data.content[keys[i]]["receiverName"] + '"' + 'data-phone="' + data.content[keys[i]]["receiverPhone"] + '"' + 'data-city="' + data.content[keys[i]]["cityCode"] + '"' + 'data-province="' + data.content[keys[i]]["provinceCode"] + '"' + 'data-town="' + data.content[keys[i]]["townCode"] + '"' + 'data-address="' + data.content[keys[i]]["detailAddress"] + '"' + ' href="javascript:void(0);'  + '">' + '查看地址</a>'
                                        }

                                    }

                                    var paddingString = "";

                                    if (data.content[keys[i]]["giftCode"] === "8080") {
                                        paddingString = "未中奖";
                                    } else {
                                        paddingString = "恭喜您获得";
                                    }
         
                                    str = str + '<p>' + paddingString +'<span class="yellow">' + (common.prize[data.content[keys[i]].giftCode] ? common.prize[data.content[keys[i]].giftCode].title : "") + realityString + '</span></p>';

                                }

                            } else if (Object.keys(data.content).length === 0) {
                                str = '<p class="t-c">暂无中奖记录</p>';
                            } else {
                                str = '<p class="t-c">暂无中奖记录</p>';
                            }

                            layer.open({
                                title: '中奖记录',
                                className: 'lotteryRecord',
                                content: str + '<div class="button">确定</div>',
                                style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                                shadeClose: false,
                                end: function () {
                                }
                            });
                            $(".lotteryRecord  .button").on("click", function () {
                                layer.closeAll();
                                getLotteryCount();
                            })
                            return
                        }
                    }
                })

            } else {
                login(2);
            }
        })
        initSugoio('');

        function getCity(data) {
            var a = b = c = '';
            $.each(window.cityData, function (i, province) {
                if (province.code === data.provinceCode) {
                    a = province.name + ' ';
                    $.each(province.sub, function (i, city) {
                        if (city.code === data.cityCode) {
                            b = city.name + ' ';
                            $.each(city.sub, function (i, town) {
                                if (town.code === data.townCode) {
                                    c = town.name + ' ';
                                }
                            })
                        }
                    })
                }
            })
            return a + b + c;
        }


        $("#container").on("click", ".addressDetailModal", function() {
            console.log("sucksuck")
            var name = $(this).data("name");
            var phone = $(this).data("phone");
            var city = $(this).data("city");
            var province = $(this).data("province");
            var town = $(this).data("town");
            var address = $(this).data("address");

            var str = '<div class=""><div><div class=""><div class="form-item"><label>姓名</label><div><input data-code="receiverName" disabled="disabled" type="text" id="name"></div></div>' +
                      '<div class="form-item"><label>联系电话</label><div><input data-code="receiverPhone" disabled="disabled" type="tel" id="tel"></div></div><div class="form-item"><label>地址</label><div class=""><input class="input-pch" data-code="city" type="text" disabled="disabled" placeholder="请选择城市" id="city"></div></div>' +
                      '<div class="form-item"><label>门牌号</label><div><input data-code="detailAddress" disabled="disabled" type="text" id="address"></div></div><div class="form-item t-c"></div></div></div></div>'

            layer.open({
                title: '查看收货地址',
                className: 'addressFormDetailForm',
                content: str + '<div style="text-align:center">' + '<button class="button" id="cancel">取消</button>' + '</div>',
                style: 'width:17rem;max-width:17rem;background-color:#fff;border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                shadeClose: false,

            });
            $(".addressFormDetailForm  #cancel").on("click", function () {
                layer.closeAll();
                getLotteryCount();
            });

            $('input[data-code="receiverName"]').val(name);
            $('input[data-code="receiverPhone"]').val(phone);
            $('input[data-code="city"]').val(getCity({
                cityCode: city,
                townCode: town,
                provinceCode: province,
            }));
            $('input[data-code="detailAddress"]').val(address);
                
                   
        });


        $("#container").on("click", ".addressModal", function () {
            console.log("sssss");
            var qualiSeqNo = $(this).data("quali");
            $(".drawNotice  .button").click();

           var str =  '<div class="content_jgg">' + '<div>' + '<div><div class="form-item">' +
                '<label>姓名</label>' + '<div><input data-code="receiverName" type="text" id="name"></div>' + '</div><div class="form-item"><label>联系电话</label><div>' +
                '<input data-code="receiverPhone" type="tel" id="tel"></div></div>' + '<div class="form-item"><label>地址</label><div class="arrow"><input class="input-pch" data-code="city" type="text" placeholder="请选择城市" id="city"></div></div>' +
                '<div class="form-item"><label>门牌号</label><div><input data-code="detailAddress" type="text" id="address"></div></div><div class="form-item t-c"></div></div></div></div>'
            
            

            layer.open({
                title: '填写收货地址',
                className: 'addressFormModal',
                content: str + '<div style="text-align:center">' + '<button class="button" style="margin-right:10px" id="submitAddress">提交</button>' + '<button class="button" id="cancel">取消</button>' + '</div>',
                style: 'width:17rem;max-width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                shadeClose: false,
                end: function () {
                    // if (!(lottery.data.status == 1)) {
                    //     location.href = common.skipUrl;
                    // }
                }
            });
            $(".addressFormModal  #cancel").on("click", function () {
                layer.closeAll();
                getLotteryCount();
            });
            $(".addressFormModal").on("click", "#cancel" ,function () {
                layer.closeAll();
                getLotteryCount();
            });
            $(".addressFormModal  #submitAddress").on("click", function () {
                var codes = $('#city').attr('data-codes');
            var codeArr = codes ? codes.split(',') : [];
            var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
            var params = {
                cardNo: JSON.parse(localStorage.getItem('isLogin')).staffNum,
                receiverName: $('#name').val(),
                receiverPhone: $('#tel').val(),
                provinceCode: codeArr[0],
                cityCode: codeArr[1],
                townCode: codeArr[2],
                detailAddress: $('#address').val()
            }
            var msg = "";
            for (var k in params) {
                if (!params[k]) {
                    if (k == 'provinceCode' || k == 'cityCode' || k == 'townCode') {
                        msg = $('[data-code="city"]').closest('.form-item').find('label').text() + '不能为空！';
                    } else {
                        msg = $('[data-code=' + k + ']').closest('.form-item').find('label').text() + '不能为空！';
                    }
                    break;
                }
                if (k == 'receiverName' && params[k].length > 10) {
                    msg = '姓名长度不能超过10位！';
                    break;
                }
                if (k == 'receiverPhone' && !reg.test(params[k])) {
                    msg = '联系电话格式不正确！';
                    break;
                }
                if (k == 'detailAddress' && params[k].length > 100) {
                    msg = '门牌号长度不能超过100！';
                    break;
                }
            }
            if (msg) {
                layer.open({
                    type: 3,
                    title: '温馨提示',
                    className: 'errortNotice',
                    content: '<div class="notice">' + msg + '</div><div id="errorButton" class="button">确定</div>',
                    style: 'width:17rem; background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                    shadeClose: false,
                });
                $(".errortNotice  .button").on("click", function () {
                    layer.close($(".errortNotice #errorButton").closest(".layermbox").attr("index"));
                    getLotteryCount();
                })
            } else {
                var t = +new Date();
                var urlSplit = window.location.href.split("/");
                $.ajax({
                    url: common.url + "/auldraw/address/create",
                    type: 'POST',
                    data: JSON.stringify({
                        dealerNo: JSON.parse(localStorage.getItem("isLogin")).staffNum,
                        receiverName: $('#name').val(),
                        receiverPhone: $('#tel').val(),
                        provinceCode: codeArr[0],
                        cityCode: codeArr[1],
                        townCode: codeArr[2],
                        detailAddress: $('#address').val(),
                        qualiSeqNo: qualiSeqNo,
                    }),
                    contentType: 'application/json;charset=UTF-8',
                    dataType: 'json',
                    beforeSend: function () {
                        loading(1);
                    },
                    complete: function () {
                        loading();
                    },
                    success: function (data) {
                        if (data && data.code == 0) {
                            layer.open({
                                title: '温馨提示',
                                className: 'drawNotice',
                                content: '<div style="font-size:20px" class="zjnotice t-c">' + data.content +
                                    '</div><div class="button">' + '关闭' + '</div>' + (common.skipUrl ? '<div class="button">' + '<a style="text-decoration: none; color: #ff8800;" href="' + common.skipUrl  + '">返回</a>' + '</div>' : ''),
                                style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                                shadeClose: false,
                                end: function () {

                                }
                            });
                            $(".drawNotice  .button").on("click", function () {
                                layer.closeAll();
                                getLotteryCount();
                            })
                        }
                    },
                    error: function (err) {

                    },

                })
            }
            });

            $(function () {
                var city = cityData;
                $("#city").cityPicker({
                    title: "请选择收货地址",
                    raw: city
                });
            })
        });


        function initSugoio(staffNum) {
            _app_name = "无限极服务号";
            _app_version = "1.1.1";
            _user_id = staffNum;
            jQuery.getScript("./js/sugoio.js", function (data, status, jqxhr) {

            });
        }

        window.onload = function () {
            getLotteryCount();
        }
    </script>
    <style>
        #cnzz_stat_icon_1275024165 {
            display: none;
        }


        .layermcont .button {
            height: 1.66rem;
            line-height: 1.66rem;
            font-size: 20px;
            /* position: absolute;
            top:17rem;
            width: 88%; */
        }

        .layermchild {
            font-size: 22px;
        }

        .login-popuo .layermcont {
            height: 11rem;
        }

        .login-popuo .layermcont .button {
            height: 1.66rem;
            line-height: 1.66rem;
            font-size: 20px;
            position: static;
            width: 100%;
        }

        .layermcont {
            line-height: 2.0rem;
            height: 16rem;
            overflow: scroll;
            font-size: 14px
        }

        .button {
            font-size: 32px;
            height: 1rem;
            text-align: center;
            line-height: 1rem;
            /* background-color: #58a0ea; */
            background-color: transparent !important;
            border: 1px solid #ff9800 !important;
            border-radius: 5px;
        }

        .layermcont .zjnotice {
            line-height: 1.8rem;
        }

        .layui-m-layerchild h3 {
            font-size: 36px;
            margin-top: 0.2rem;
        }

        .startNotice .button,
        .errortNotice .button,
        .drawNotice .button,
        .againNotice .button,
        .notNotice .button {
            height: 1.66rem;
            line-height: 1.66rem;
            border: 1px solid #ff9800 !important;
            color: #ff9800;
            /* position: absolute;
            top: 15rem;
            width: 88%; */
        }

        .layui-m-layercont {
            font-size: 26px;
            padding: 30px 30px;
        }

        .layui-m-layerchild.startNotice.layui-m-anim-scale h3 {
            background-color: transparent !important;
            color: black !important;
        }

        .layermchild.errortNotice.layermanim .button {
            height: 1.6rem;
            line-height: 1.6rem;
        }
        .addressFormModal .layermcont {
            height: 22rem;
        }
        .addressFormModal .layermcont .button {
            height: 1.66rem;
            line-height: 1.66rem;
            font-size: 20px;
            position: static;
            width: 100%;
        }
        .addressFormDetailForm .layermcont .button {
            height: 1.66rem;
            line-height: 1.66rem;
            font-size: 20px;
            position: static;
            width: 100%;
        }

        html {
            touch-action: none
        }

        .errortNotice .layermcont {
            height: 6rem!important
        }

        .startNotice .layermcont {
            height: 6rem!important
        }

        input::-webkit-input-placeholder{
      font-size:16px;
        }
        input::-moz-placeholder{   /* Mozilla Firefox 19+ */
          font-size:16px;
        }
        input:-moz-placeholder{    /* Mozilla Firefox 4 to 18 */
          font-size:16px;
        }
        input:-ms-input-placeholder{  /* Internet Explorer 10-11 */ 
          font-size:16px;
        }
        .drawNotice .layermcont {
            height: 7.6rem;
        }
        .address_modal {
            height: 2rem;
            text-align: center;
            line-height: 2rem;
            background-color: transparent;
            border-radius: 5px;
            border: 1px solid #ff9800!important;
            color: #ff9800;
            font-size: 18px;
        }


    </style>
    <script type="text/javascript">
        var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
        document.write(unescape("%3Cspan id='cnzz_stat_icon_1275024165'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol +
            "s19.cnzz.com/z_stat.php%3Fid%3D1275024165' type='text/javascript'%3E%3C/script%3E"));
    </script>
    
</body>

</html>